# -*- coding: UTF-8 -*-
# __author__ = '10459'

#可处理控制变量，不一定是展示前端页面的
from app.libs.enums import PendingStatus


class DriftViewModel:
    def __init__(self,drift,current_user_id):
        self.data={}
        self.data = self.__perse(drift,current_user_id)
    def requester_or_gifter(self,drift,current_user_id):
        if drift.requester_id == current_user_id:
            you_are = "requester"
        else:
            you_are = "gifter"
        return you_are
    def __perse(self,drift,current_user_id):
        you_are = self.requester_or_gifter(drift,current_user_id)
        pending_status = PendingStatus.pending_str(drift.pending,you_are)
        #如果是请求者，则显示向他请求也就是赠送者名字，如果不是请求者，则显示请求者也就是请求者名字
        r ={
            'you_are':you_are,
            'drift_id':drift.id,
            'book_title':drift.book_title,
            'book_author':drift.book_author,
            'book_img':drift.book_img,
            'date':drift.create_datetime.strftime("%Y-%m-%d"),
            'operator':drift.requester_nickname if you_are !='requester'
            else drift.gifter_nickname,
            'message':drift.message,
            'address':drift.address,
            'recipient_name':drift.recipient_name,
            'mobile':drift.mobile,
            'status':drift.pending,
            'status_str':pending_status
        }
        return r
class DriftCollection:
    def __init__(self,drifts,current_user_id):
        self.data=[]

        self.__parse(drifts,current_user_id)

    def __parse(self,drifts,current_user_id):
        for drift in drifts:
            temp = DriftViewModel(drift,current_user_id)
            self.data.append(temp.data)